package com.hnevc.androiduiclassone8;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        String fileName = "data.txt";
        String content ="王家珏";
        FileOutputStream fos;
        try{
            fos = openFileOutput(fileName,MODE_PRIVATE);
            byte[] bytes = content.getBytes();
            fos.write(bytes);
            fos.close();
        }catch (Exception e){

    }
        Log.e("TAG", "onCreate: ==========" );

        FileInputStream fis = null;
        try {
            fis = openFileInput(fileName);
            byte[] buffer = new byte[fis.available()];
            fis.read(buffer);
            String temp = new String(buffer);
            Toast.makeText(this,temp,  Toast.LENGTH_SHORT).show();
        }catch (IOException e){
            e.printStackTrace();
        }
}}
